bitkeeper revision 1.1159.198.1 (41aa44a7joSgzez98niBGEZAU1bASg)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Sun, 28 Nov 2004 21:35:35 +0000 (21:35 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Sun, 28 Nov 2004 21:35:35 +0000 (21:35 +0000)
Get rid of all our uses of virt_to_phys():
 1. Many were buggy, so the code needed fixing or clarifying anyway
 2. It means we can now experiment with kludging virt_to_phys() to be
    the same as virt_to_bus(), to get more buggy drivers working. I haven't
    included the kludge in this patch.

linux-2.4.28-xen-sparse/arch/xen/kernel/ldt.c
linux-2.4.28-xen-sparse/include/asm-xen/pgtable.h
linux-2.6.9-xen-sparse/arch/xen/i386/kernel/ldt.c
linux-2.6.9-xen-sparse/arch/xen/i386/kernel/setup.c
linux-2.6.9-xen-sparse/arch/xen/i386/mm/init.c
linux-2.6.9-xen-sparse/arch/xen/i386/mm/ioremap.c
linux-2.6.9-xen-sparse/arch/xen/i386/mm/pgtable.c
linux-2.6.9-xen-sparse/include/asm-xen/asm-i386/io.h
linux-2.6.9-xen-sparse/include/asm-xen/asm-i386/pgtable.h

index 9e14b0855b5975e295b8223495c1368ec9a8b0ff..374c9b6c30b48212148911cd7e3c4b25f67849d8 100644 (file)
@@ -179,7 +179,7 @@ static int write_ldt(void * ptr, unsigned long bytecount, int oldmode)
 {
        struct mm_struct * mm = current->mm;
        __u32 entry_1, entry_2, *lp;
-       unsigned long phys_lp;
+       unsigned long mach_lp;
        int error;
        struct modify_ldt_ldt_s ldt_info;
 
@@ -208,7 +208,7 @@ static int write_ldt(void * ptr, unsigned long bytecount, int oldmode)
        }
 
        lp = (__u32 *) ((ldt_info.entry_number << 3) + (char *) mm->context.ldt);
-       phys_lp = arbitrary_virt_to_phys(lp);
+       mach_lp = arbitrary_virt_to_machine(lp);
 
        /* Allow LDTs to be cleared by the user. */
        if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
@@ -241,7 +241,7 @@ static int write_ldt(void * ptr, unsigned long bytecount, int oldmode)
 
        /* Install the new entry ...  */
 install:
-       error = HYPERVISOR_update_descriptor(phys_lp, entry_1, entry_2);
+       error = HYPERVISOR_update_descriptor(mach_lp, entry_1, entry_2);
 
 out_unlock:
        up(&mm->context.sem);
index d3ece3a2a54a64cf6cde6fa1d9c9e1128584793f..c15f0e9509b4e480e980bc0f43e933bafd613392 100644 (file)
@@ -350,7 +350,7 @@ static inline void make_pages_writable(void *va, unsigned int nr)
     }
 }
 
-static inline unsigned long arbitrary_virt_to_phys(void *va)
+static inline unsigned long arbitrary_virt_to_machine(void *va)
 {
     pgd_t *pgd = pgd_offset_k((unsigned long)va);
     pmd_t *pmd = pmd_offset(pgd, (unsigned long)va);
index 1a762ce99b25318de6533649b33f34559bf9ca98..3b8ae7077407aeaa84b39c1335cd937835c8252f 100644 (file)
@@ -193,7 +193,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
 {
        struct mm_struct * mm = current->mm;
        __u32 entry_1, entry_2, *lp;
-       unsigned long phys_lp;
+       unsigned long mach_lp;
        int error;
        struct user_desc ldt_info;
 
@@ -222,7 +222,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
        }
 
        lp = (__u32 *) ((ldt_info.entry_number << 3) + (char *) mm->context.ldt);
-       phys_lp = arbitrary_virt_to_phys(lp);
+       mach_lp = arbitrary_virt_to_machine(lp);
 
        /* Allow LDTs to be cleared by the user. */
        if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
@@ -240,7 +240,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
 
        /* Install the new entry ...  */
 install:
-       error = HYPERVISOR_update_descriptor(phys_lp, entry_1, entry_2);
+       error = HYPERVISOR_update_descriptor(mach_lp, entry_1, entry_2);
 
 out_unlock:
        up(&mm->context.sem);
index c9574a4311f63e6ff52ccccb5b6cd131390ffac6..8eb0add9d67c5c3a656ef1156adec4b49d56ae82 100644 (file)
@@ -1389,10 +1389,11 @@ void __init setup_arch(char **cmdline_p)
        init_mm.end_data = (unsigned long) _edata;
        init_mm.brk = (PFN_UP(__pa(xen_start_info.pt_base)) + xen_start_info.nr_pt_frames) << PAGE_SHIFT;
 
-       code_resource.start = virt_to_phys(_text);
-       code_resource.end = virt_to_phys(_etext)-1;
-       data_resource.start = virt_to_phys(_etext);
-       data_resource.end = virt_to_phys(_edata)-1;
+       /* XEN: This is nonsense: kernel may not even be contiguous in RAM. */
+       /*code_resource.start = virt_to_phys(_text);*/
+       /*code_resource.end = virt_to_phys(_etext)-1;*/
+       /*data_resource.start = virt_to_phys(_etext);*/
+       /*data_resource.end = virt_to_phys(_edata)-1;*/
 
        parse_cmdline_early(cmdline_p);
 
index 74704113e65e2942d442e0f1245e6df905f95143..0a403abb51d5709f2404fa3636af1fa9bdfa1122 100644 (file)
@@ -435,17 +435,24 @@ void zap_low_mappings (void)
 void __init zone_sizes_init(void)
 {
        unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
-       unsigned int max_dma, high, low;
+       unsigned int /*max_dma,*/ high, low;
        
-       max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
+       /*
+        * XEN: Our notion of "DMA memory" is fake when running over Xen.
+        * We simply put all RAM in the DMA zone so that those drivers which
+        * needlessly specify GFP_DMA do not get starved of RAM unnecessarily.
+        * Those drivers that *do* require lowmem are screwed anyway when
+        * running over Xen!
+        */
+       /*max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;*/
        low = max_low_pfn;
        high = highend_pfn;
        
-       if (low < max_dma)
+       /*if (low < max_dma)*/
                zones_size[ZONE_DMA] = low;
-       else {
-               zones_size[ZONE_DMA] = max_dma;
-               zones_size[ZONE_NORMAL] = low - max_dma;
+       /*else*/ {
+               /*zones_size[ZONE_DMA] = max_dma;*/
+               /*zones_size[ZONE_NORMAL] = low - max_dma;*/
 #ifdef CONFIG_HIGHMEM
                zones_size[ZONE_HIGHMEM] = high - low;
 #endif
index 5e140759c32f34dc7bd8c65f2502985b19db8c41..34c91fbe3de8d3ad082da933a86f0d6cb3d6e351 100644 (file)
@@ -36,6 +36,23 @@ void __init bt_iounmap(void *addr, unsigned long size)
 
 #else
 
+/*
+ * Is @address within a RAM page that is local to this virtual machine (i.e.,
+ * not an I/O page; not a RAM page belonging to another VM). See the comment
+ * that accompanies pte_pfn() in pgtable-2level.h to understand why this works.
+ */
+static inline int is_local_ram(unsigned long address)
+{
+       unsigned long mfn = address >> PAGE_SHIFT;
+       unsigned long pfn = mfn_to_pfn(mfn);
+       if (pfn < max_mapnr) {
+               if (pfn_to_mfn(pfn) == mfn)
+                       return 1; /* local ram */
+               printk("is_local_ram: ioremapping foreign ram (a bad idea).\n");
+       }
+       return 0; /* i/o memory or foreign ram */
+}
+
 static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
        unsigned long phys_addr, unsigned long flags)
 {
@@ -140,19 +157,16 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l
        if (!size || last_addr < phys_addr)
                return NULL;
 
-        if (phys_addr >= 0x0 && last_addr < 0x100000)
-                return isa_bus_to_virt(phys_addr);
-
        /*
         * Don't remap the low PCI/ISA area, it's always mapped..
         */
-       if (phys_addr >= 0xA0000 && last_addr < 0x100000)
-               return (void __iomem *) phys_to_virt(phys_addr);
+       if (phys_addr >= 0x0 && last_addr < 0x100000)
+               return isa_bus_to_virt(phys_addr);
 
        /*
         * Don't allow anybody to remap normal RAM that we're using..
         */
-       if (machine_to_phys(phys_addr) < virt_to_phys(high_memory)) {
+       if (is_local_ram(phys_addr)) {
                char *t_addr, *t_end;
                struct page *page;
 
@@ -219,7 +233,7 @@ void __iomem *ioremap_nocache (unsigned long phys_addr, unsigned long size)
        /* Guaranteed to be > phys_addr, as per __ioremap() */
        last_addr = phys_addr + size - 1;
 
-       if (machine_to_phys(last_addr) < virt_to_phys(high_memory)) { 
+       if (is_local_ram(last_addr)) { 
                struct page *ppage = virt_to_page(bus_to_virt(phys_addr));
                unsigned long npages;
 
@@ -256,7 +270,7 @@ void iounmap(volatile void __iomem *addr)
                return;
        } 
 
-       if (p->flags && machine_to_phys(p->phys_addr) < virt_to_phys(high_memory)) { 
+       if (p->flags && is_local_ram(p->phys_addr)) { 
                change_page_attr(virt_to_page(bus_to_virt(p->phys_addr)),
                                 p->size >> PAGE_SHIFT,
                                 PAGE_KERNEL);                           
@@ -276,14 +290,11 @@ void __init *bt_ioremap(unsigned long phys_addr, unsigned long size)
        if (!size || last_addr < phys_addr)
                return NULL;
 
-        if (phys_addr >= 0x0 && last_addr < 0x100000)
-                return isa_bus_to_virt(phys_addr);
-
        /*
         * Don't remap the low PCI/ISA area, it's always mapped..
         */
-       if (phys_addr >= 0xA0000 && last_addr < 0x100000)
-               return phys_to_virt(phys_addr);
+       if (phys_addr >= 0x0 && last_addr < 0x100000)
+               return isa_bus_to_virt(phys_addr);
 
        /*
         * Mappings have to be page-aligned
index 2fadb97535a09488583aecba47050fae3493e6a0..10262674fc44c985399f10c4419a9f2132875ffa 100644 (file)
@@ -195,7 +195,7 @@ void pte_ctor(void *pte, kmem_cache_t *cache, unsigned long unused)
 
        clear_page(pte);
        make_page_readonly(pte);
-       queue_pte_pin(virt_to_phys(pte));
+       queue_pte_pin(__pa(pte));
        flush_page_update_queue();
 }
 
@@ -204,7 +204,7 @@ void pte_dtor(void *pte, kmem_cache_t *cache, unsigned long unused)
        struct page *page = virt_to_page(pte);
        ClearPageForeign(page);
 
-       queue_pte_unpin(virt_to_phys(pte));
+       queue_pte_unpin(__pa(pte));
        make_page_writable(pte);
        flush_page_update_queue();
 }
index 0a2de0bb925eea609ad7034cb9c4a964425f9fbb..2064f2d69ab9a92936db5175325189dce8e58c37 100644 (file)
@@ -146,8 +146,8 @@ extern void bt_iounmap(void *addr, unsigned long size);
  *
  * Allow them on x86 for legacy drivers, though.
  */
-#define virt_to_bus(_x) phys_to_machine(virt_to_phys(_x))
-#define bus_to_virt(_x) phys_to_virt(machine_to_phys(_x))
+#define virt_to_bus(_x) phys_to_machine(__pa(_x))
+#define bus_to_virt(_x) __va(machine_to_phys(_x))
 
 /*
  * readX/writeX() are used to access memory mapped devices. On some
index db97836850ca7feb1745aca9807af1dbfca36d2c..4f4706ddbb4921a66bde018ae43c6400a21c87fc 100644 (file)
@@ -472,7 +472,7 @@ void make_page_writable(void *va);
 void make_pages_readonly(void *va, unsigned int nr);
 void make_pages_writable(void *va, unsigned int nr);
 
-static inline unsigned long arbitrary_virt_to_phys(void *va)
+static inline unsigned long arbitrary_virt_to_machine(void *va)
 {
        pgd_t *pgd = pgd_offset_k((unsigned long)va);
        pmd_t *pmd = pmd_offset(pgd, (unsigned long)va);